﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace TinyCms.Core.Repositories
{
    public interface IRepository<T> where T:EntityBase
    {
        /// <summary>
        /// 仓储上下文
        /// </summary>
        IRepositoryContext Context { get; }
        /// <summary>
        /// 根据主键获取对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T GetByKey(Guid id);

        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns></returns>
        IEnumerable<T> GetAll();

        IEnumerable<T> GetAll(Expression<Func<T, dynamic>> sort, SortOrder order=SortOrder.Ascending);
        /// <summary>
        /// 根据条件获取
        /// </summary>
        /// <param name="pre"></param>
        /// <returns></returns>
        IEnumerable<T> GetAll(Expression<Func<T, bool>> pre);

        IEnumerable<T> GetAll(Expression<Func<T, bool>> pre, Expression<Func<T, dynamic>> sort, SortOrder order = SortOrder.Ascending);
        /// <summary>
        /// 根据条件获取分页数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pagesize"></param>
        /// <param name="count"></param>
        /// <param name="pre"></param>
        /// <returns></returns>
        IEnumerable<T> GetPageList(int pageIndex, int pagesize, out int count, Expression<Func<T, bool>> pre);

        IEnumerable<T> GetPageList(int pageIndex, int pagesize, out int count, Expression<Func<T, bool>> pre,
                                   Expression<Func<T, dynamic>> sort, SortOrder order = SortOrder.Ascending);

        void Add(T entity);
        void Add(List<T> entities);

        void Update(T entity);
        void Update(List<T> entity);

        void Delete(T entity);
        void Delete(List<T> entity);

        int ExecuteCommand(string command);
        IEnumerable<T> ExecuteQuery(string query);

    }
}
